package com.gitee.wsl.ext.number


/** Signs of the value. Zero will be converted into -1 */
val Int.signM1: Int get() = signNonZeroM1(this)
/** Signs of the value. Zero will be converted into -1 */
val Float.signM1: Float get() = signNonZeroM1(this).toFloat()
/** Signs of the value. Zero will be converted into -1 */
val Double.signM1: Double get() = signNonZeroM1(this).toDouble()

/** Signs of the value. Zero will be converted into +1 */
val Int.signP1: Int get() = signNonZeroP1(this)
/** Signs of the value. Zero will be converted into +1 */
val Float.signP1: Float get() = signNonZeroP1(this).toFloat()
/** Signs of the value. Zero will be converted into +1 */
val Double.signP1: Double get() = signNonZeroP1(this).toDouble()

/** Signs of the value. Zero will be converted into -1 */
fun signNonZeroM1(x: Int): Int = if (x <= 0) -1 else +1
/** Signs of the value. Zero will be converted into -1 */
fun signNonZeroM1(x: Float): Int = if (x <= 0) -1 else +1
/** Signs of the value. Zero will be converted into -1 */
fun signNonZeroM1(x: Double): Int = if (x <= 0) -1 else +1


/** Signs of the value. Zero will be converted into +1 */
fun signNonZeroP1(x: Int): Int = if (x >= 0) +1 else -1
/** Signs of the value. Zero will be converted into +1 */
fun signNonZeroP1(x: Float): Int = if (x >= 0) +1 else -1
/** Signs of the value. Zero will be converted into +1 */
fun signNonZeroP1(x: Double): Int = if (x >= 0) +1 else -1